﻿Imports System.Collections.Generic

Imports System

Imports Microsoft.VisualStudio.TestTools.UnitTesting

Imports NotBasic.Compiler.Semantic



'''<summary>
'''This is a test class for QualifierTest and is intended
'''to contain all QualifierTest Unit Tests
'''</summary>
<TestClass()> _
Public Class QualifierTest


    Private testContextInstance As TestContext

    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(ByVal value As TestContext)
            testContextInstance = Value
        End Set
    End Property

#Region "Additional test attributes"
    '
    'You can use the following additional attributes as you write your tests:
    '
    'Use ClassInitialize to run code before running the first test in the class
    '<ClassInitialize()>  _
    'Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    'End Sub
    '
    'Use ClassCleanup to run code after all tests in a class have run
    '<ClassCleanup()>  _
    'Public Shared Sub MyClassCleanup()
    'End Sub
    '
    'Use TestInitialize to run code before running each test
    '<TestInitialize()>  _
    'Public Sub MyTestInitialize()
    'End Sub
    '
    'Use TestCleanup to run code after each test has run
    '<TestCleanup()>  _
    'Public Sub MyTestCleanup()
    'End Sub
    '
#End Region


    '''<summary>
    '''A test for ToString
    '''</summary>
    <TestMethod()> _
    Public Sub ToStringTest()
        Dim target As New QualifierBuilder
        With target
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("A"), _
                         .Connector = QualifierSection.TopLevelConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("BB"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("CCc"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("DDdD"), _
                         .Connector = QualifierSection.NestedTypeConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("E"), _
                         .Connector = QualifierSection.MemberConnector})
        End With

        Dim expected As String = "A.BB.CCc+DDdD.E"
        Dim actual As String
        actual = target.BuildQualifier.ToString
        Assert.AreEqual(expected, actual)
    End Sub

    '''<summary>
    '''A test for ToList
    '''</summary>
    <TestMethod()> _
    Public Sub ToListTest()
        Dim expected As New List(Of Symbol)
        With expected
            .Add(Symbol.Get("A"))
            .Add(Symbol.Get("BB"))
            .Add(Symbol.Get("CCc"))
            .Add(Symbol.Get("DDdD"))
            .Add(Symbol.Get("E"))
        End With

        Dim target As New QualifierBuilder

        With target
            .PushSection(New QualifierSection With { _
             .Name = Symbol.Get("A"), _
             .Connector = QualifierSection.TopLevelConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("BB"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("CCc"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("DDdD"), _
                         .Connector = QualifierSection.NestedTypeConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("E"), _
                         .Connector = QualifierSection.MemberConnector})
        End With

        Dim actual = target.BuildQualifier

        Assert.AreEqual(expected.Count, actual.Count)

        For i = 0 To expected.Count - 1
            Assert.AreEqual(expected(i), actual(i).Name)
        Next

    End Sub

    '''<summary>
    '''A test for PopSection
    '''</summary>
    <TestMethod()> _
    Public Sub PopSectionTest()
        Dim target As New QualifierBuilder
        With target
            .PushSection(New QualifierSection With { _
             .Name = Symbol.Get("A"), _
             .Connector = QualifierSection.TopLevelConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("BB"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("CCc"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("DDdD"), _
                         .Connector = QualifierSection.NestedTypeConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("E"), _
                         .Connector = QualifierSection.MemberConnector})
        End With

        Dim expected As QualifierSection = New QualifierSection With { _
                         .Name = Symbol.Get("E"), _
                         .Connector = QualifierSection.MemberConnector}

        Dim actual As QualifierSection
        actual = target.PopSection
        Assert.AreEqual(expected, actual)
    End Sub

    '''<summary>
    '''A test for GetHashCode
    '''</summary>
    <TestMethod()> _
    Public Sub GetHashCodeTest()
        Dim target As New QualifierBuilder
        With target
            .PushSection(New QualifierSection With { _
             .Name = Symbol.Get("A"), _
             .Connector = QualifierSection.TopLevelConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("BB"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("CCc"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("DDdD"), _
                         .Connector = QualifierSection.NestedTypeConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("E"), _
                         .Connector = QualifierSection.MemberConnector})
            .PopSection()
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("fF"), _
                         .Connector = QualifierSection.NestedTypeConnector})
        End With

        Dim compare As New QualifierBuilder
        With compare
            .PushSection(New QualifierSection With { _
             .Name = Symbol.Get("A"), _
             .Connector = QualifierSection.TopLevelConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("BB"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("CCc"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("DDdD"), _
                         .Connector = QualifierSection.NestedTypeConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("fF"), _
                         .Connector = QualifierSection.NestedTypeConnector})
        End With

        Dim expected As Integer = compare.BuildQualifier.GetHashCode
        Dim actual As Integer
        actual = target.BuildQualifier.GetHashCode
        Assert.AreEqual(expected, actual)
    End Sub

    '''<summary>
    '''A test for Equals
    '''</summary>
    <TestMethod()> _
    Public Sub EqualsTest1()
        Dim target As New QualifierBuilder ' TODO: Initialize to an appropriate value
        Dim obj As Object = Nothing ' TODO: Initialize to an appropriate value
        Dim expected As Boolean = False ' TODO: Initialize to an appropriate value
        Dim actual As Boolean
        actual = target.BuildQualifier.Equals(obj)
        Assert.AreEqual(expected, actual)
    End Sub

    '''<summary>
    '''A test for Equals
    '''</summary>
    <TestMethod()> _
    Public Sub EqualsTest()
        Dim target As New QualifierBuilder
        With target
            .PushSection(New QualifierSection With { _
             .Name = Symbol.Get("A"), _
             .Connector = QualifierSection.TopLevelConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("BB"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("CCc"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("DDdD"), _
                         .Connector = QualifierSection.NestedTypeConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("E"), _
                         .Connector = QualifierSection.MemberConnector})
            .PopSection()
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("fF"), _
                         .Connector = QualifierSection.NestedTypeConnector})
        End With

        Dim compare As New QualifierBuilder
        With compare
            .PushSection(New QualifierSection With { _
             .Name = Symbol.Get("A"), _
             .Connector = QualifierSection.TopLevelConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("BB"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("CCc"), _
                         .Connector = QualifierSection.NamespaceConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("DDdD"), _
                         .Connector = QualifierSection.NestedTypeConnector})
            .PushSection(New QualifierSection With { _
                         .Name = Symbol.Get("fF"), _
                         .Connector = QualifierSection.NestedTypeConnector})
        End With
        Dim expected As Boolean = True ' TODO: Initialize to an appropriate value
        Dim actual As Boolean
        actual = target.BuildQualifier.Equals(compare.BuildQualifier)
        Assert.AreEqual(expected, actual)
    End Sub
End Class
